<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>二维码登录</title>
    <script type="text/javascript" src="/static/js/jq.js"></script>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
<div style="text-align: center;">
    <img src="/captcha/getCaptcha?type=1" width="130px" height="48px"/>
    <img id="code" style="height: 10em;width: 10em;margin:20em auto 0 auto"/>
    <div>
        <button id="twiceGetCode" style="display: none;" onclick="getCode()">重新获取二维码</button>
    </div>
</div>
</body>
<script type="application/javascript">
    $(function(){
        getCode();
        $.ajax({
            type:"get",
            url:"/captcha/getCaptcha?type=1",
            dataType:"json",
            success:function (data) {
                console.log(data)
            }
        })
    });
    function getCode() {
        $("#twiceGetCode").hide();
        $.ajax({
            type:"get",
            url:"/login/loginQrCode.json",
            dataType:"json",
            success:function (res) {
                if (res.code==1){
                    $("#code").attr("src",res.src);
                    var count=0;
                    var checkLogin=setInterval(
                        function () {
                            $.ajax({
                                type:"get",
                                url:"/login/getLoginStatus.json",
                                data:res.token,
                                dataType:"json",
                                success:function (data) {
                                    count++;
                                    if (data.code==1){
                                        clearInterval(checkLogin);
                                        alert("登录成功");
                                    }else if(count==30) {
                                        clearInterval(checkLogin);
                                        $("#code").attr("src",null);
                                        alert("登录超时");
                                        $("#twiceGetCode").show();
                                    }
                                }
                            })
                        },2000)
                }
            }
        });
    }
</script>
</html>